package com.bawei.mall.search.controller;

import com.bawei.common.core.domain.R;
import com.bawei.mall.search.domain.Po.ReadHistory;
import com.bawei.mall.search.domain.Vo.DetailVo;
import com.bawei.mall.search.service.ReadHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：liurui
 * @Package：com.bawei.mall.search.controller
 * @Project：mall_cloud
 * @name：ReadHistoryController
 */
@RestController
@Log4j2
@RequestMapping("/readHistory")
public class ReadHistoryController {
    @Autowired
    private ReadHistoryService service;

    /**
     * 我的足迹查
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public R<PageInfo<ReadHistory>> list(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<ReadHistory> list=service.list();
        PageInfo<ReadHistory> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    @GetMapping("/detail/{id}")
    public R detail(@PathVariable Integer id){
        DetailVo detailVo=service.detail(id);
        return R.ok(detailVo);
    }


    @GetMapping("/detail")
    public R productCollection(@RequestParam Integer productId){
        return R.ok();
    }

    /**
     * 我的足迹增
     * @param readHistory
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody ReadHistory readHistory){
        service.create(readHistory);
        return R.ok();
    }

    /**
     * 我的足迹删
     * @return
     */
    @PostMapping("/clear")
    public R clear(){
        service.clear();
        return R.ok();
    }

}
